package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Menu;
import com._51cto.healthy.service.MenuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @DubboReference
    private MenuService menuService;
    @GetMapping("/page/{pageSize}/{pageNum}")
    public R queryPageRole(@RequestParam(value = "query",required = false/*表示参数不是必填项*/) String query,
                           @PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize){
        P<Menu> menuP = menuService.queryMenuAll(query, pageNum, pageSize);
        return R.success(menuP,"查询成功");

    }

    @PostMapping
    public R insertMenus(@RequestBody Menu menu){
        menuService.insert(menu);
        return R.success("添加成功");
    }
    @PutMapping
    public R updateMenus(@RequestBody Menu menu){
        menuService.update(menu);
        return R.success("修改成功");
    }
    @DeleteMapping("/{id}")
    public R deleteMenus(@PathVariable("id") Integer id){
        menuService.deleteByPK(id);
        return R.success("删除成功");
    }
}
